package top.kikt.book.core.entity

import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import top.kikt.book.util.HttpUtils
import top.kikt.book.util.HttpUtils.string
import java.nio.charset.Charset

/**
 * 书的章节信息
 */
data class ChapterMetaEntity(
    /** 章节名 */
    val name: String,
    /** 章节序号, base 0 */
    val index: Int,
    /** 章节 url */
    val url: String,
    /** 章节的元素 */
    val element: Element,
) {
    fun fileName(): String {
        return "第${index}章_$name.txt".replace(" ", "_").replace("/", "_")
    }

    fun String.toDocument(): Document? {
        return Jsoup.parse(this)
    }

    fun toChapterMetaEntity(content: String): ChapterEntity {
        return ChapterEntity(name, index, content)
    }

}

